package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.relfile.domain.RelTypeFile;
import com.ruoyi.relfile.service.IRelTypeFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 类别文件关联Controller
 * 
 * @author ruoyi
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/system/typefile")
public class RelTypeFileController extends BaseController
{
    @Autowired
    private IRelTypeFileService relTypeFileService;

    /**
     * 查询类别文件关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:typefile:list')")
    @GetMapping("/list")
    public TableDataInfo list(RelTypeFile relTypeFile)
    {
        startPage();
        List<RelTypeFile> list = relTypeFileService.selectRelTypeFileList(relTypeFile);
        return getDataTable(list);
    }

    /**
     * 导出类别文件关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:typefile:export')")
    @Log(title = "类别文件关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RelTypeFile relTypeFile)
    {
        List<RelTypeFile> list = relTypeFileService.selectRelTypeFileList(relTypeFile);
        ExcelUtil<RelTypeFile> util = new ExcelUtil<RelTypeFile>(RelTypeFile.class);
        return util.exportExcel(list, "类别文件关联数据");
    }

    /**
     * 获取类别文件关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:typefile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(relTypeFileService.selectRelTypeFileById(id));
    }

    /**
     * 新增类别文件关联
     */
    @PreAuthorize("@ss.hasPermi('system:typefile:add')")
    @Log(title = "类别文件关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RelTypeFile relTypeFile)
    {
        return toAjax(relTypeFileService.insertRelTypeFile(relTypeFile));
    }

    /**
     * 修改类别文件关联
     */
    @PreAuthorize("@ss.hasPermi('system:typefile:edit')")
    @Log(title = "类别文件关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RelTypeFile relTypeFile)
    {
        return toAjax(relTypeFileService.updateRelTypeFile(relTypeFile));
    }

    /**
     * 删除类别文件关联
     */
    @PreAuthorize("@ss.hasPermi('system:typefile:remove')")
    @Log(title = "类别文件关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(relTypeFileService.deleteRelTypeFileByIds(ids));
    }
}
